package com.gps.web.comm.action;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.apache.poi.ss.usermodel.Row;

public abstract class BaseSheetAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected File spreadSheet;
	protected String spreadSheetFileName;
	protected String spreadSheetContentType;
	protected String outMessage = "";
	protected List<ColumnHeader> colHeaderList = new ArrayList<ColumnHeader>(); 
	
	protected abstract void initSheetHeader();

	protected Boolean validateSheetHeader(Row row) {
		initSheetHeader();
		int matchCount = 0;
		for(int i=0; i<colHeaderList.size(); i++){
			if(row.getLastCellNum() > i) {
				if(colHeaderList.get(i).getColumnName().trim().compareToIgnoreCase(row.getCell(i).getStringCellValue().trim()) == 0) {
					colHeaderList.get(i).setIsMatch(true);
					matchCount++;
				}
			} else {
				colHeaderList.get(i).setIsMatch(false);
			}
		}
		
		return matchCount == colHeaderList.size();
	}

	public File getSpreadSheet() {
		return spreadSheet;
	}

	public void setSpreadSheet(File spreadSheet) {
		this.spreadSheet = spreadSheet;
	}

	public String getSpreadSheetFileName() {
		return spreadSheetFileName;
	}

	public void setSpreadSheetFileName(String spreadSheetFileName) {
		this.spreadSheetFileName = spreadSheetFileName;
	}

	public String getSpreadSheetContentType() {
		return spreadSheetContentType;
	}

	public void setSpreadSheetContentType(String spreadSheetContentType) {
		this.spreadSheetContentType = spreadSheetContentType;
	}

	public String getOutMessage() {
		return outMessage;
	}

	public void setOutMessage(String outMessage) {
		this.outMessage = outMessage;
	}

	public List<ColumnHeader> getColHeaderList() {
		return colHeaderList;
	}

	public void setColHeaderList(List<ColumnHeader> colHeaderList) {
		this.colHeaderList = colHeaderList;
	}

	protected class ColumnHeader {
		private String columnName;
		private Boolean isMatch;
		
		public ColumnHeader(String columnName) {
			this.columnName = columnName;
		}
		
		public String getColumnName() {
			return columnName;
		}
		public void setColumnName(String columnName) {
			this.columnName = columnName;
		}
		public Boolean getIsMatch() {
			return isMatch;
		}
		public void setIsMatch(Boolean isMatch) {
			this.isMatch = isMatch;
		}
	}
}
